<template>
    <div class="mycomments">
        <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column
      label="用户"
      prop="userName">
    </el-table-column>
    <el-table-column
      label="留言"
      prop="comment">
    </el-table-column>
    <el-table-column
      align="center" label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">回复</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
    </div>
</template>

<script>
import {getcommentsFunc,deletecommentsFunc} from "../http/request"
  export default {
    data() {
      return {
        tableData: [
        //      {
        //   date: '2016-05-03',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1516 弄'
        // }
        ],
      }
    },
    methods: {
      handleEdit(index, row) {
        console.log(index, row);
      },
      handleDelete(index, row) {
        console.log(index, row);
        this.deleteproduct(row.cid);
        this.$router.go(0);
      },
          // 获取留言列表
    async getcomments() {
      await getcommentsFunc("/user/usercomments").then((data) => {
        console.log(data);
        this.tableData = data.result;
      });
    },
     // 删除留言
    async deleteproduct(cid) {
      await deletecommentsFunc("/user/deletecomments", { cid: cid }).then(
        (data) => {
          console.log(data);
        }
      );
    },
    },
    mounted(){
        this.getcomments();
    }
  }
</script>